package com.lan.support.page;


import com.fasterxml.jackson.annotation.JsonIgnore;

import java.io.Serializable;
import java.util.List;

public class Page<T> implements Serializable {

    private List<T> content;

    @JsonIgnore
    private PageHelper helper;

    private Integer total = 0;

    private Integer curPage;

    private Integer pageSize;

    private Integer len;

    public Page(PageHelper helper, Integer total) {
        this.total = total;
        this.helper = helper;
    }

    /**
     * @param content
     * @param helper
     * @param total
     */
    public Page(List<T> content, PageHelper helper, Integer total) {
        this.content = content;
        this.total = total;
        this.helper = helper;
        calculate();
    }

    /**
     * 计算
     */
    private void calculate() {
        this.curPage = helper.getCurPage();
        this.pageSize = helper.getPageSize();
        if ((total % pageSize) == 0) {
            len = total / pageSize;
        } else {
            len = total / pageSize + 1;
        }
    }

    /**
     * 数据列表
     *
     * @return
     */
    public List<T> getContent() {
        return content;
    }

    public void setContent(List<T> content) {
        this.content = content;
        calculate();
    }

    /**
     * 基础分页设置
     *
     * @return
     */
    public PageHelper getHelper() {
        return helper;
    }

    public void setHelper(PageHelper helper) {
        this.helper = helper;
    }


    public Integer getTotal() {
        return total;
    }


    public Integer getCurPage() {
        return curPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public Integer getLen() {
        return len;
    }
}
